﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Topics_GroupEdit : BaseTopicPage
{
    public override Acms.Bll.Role.Roles[] AllowedRoles
    {
        get { return new Acms.Bll.Role.Roles[]{Acms.Bll.Role.Roles.Developer}; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                Id = int.Parse(Request.QueryString["Id"]);
            }
            catch
            {
            }
            if (Request.QueryString["Mode"] == "Insert")
            {
                dv.ChangeMode(DetailsViewMode.Insert);
            }
            else if (Request.QueryString["Mode"] == "Edit")
            {
                dv.ChangeMode(DetailsViewMode.Edit);
            }
        }
    }

    public int Id { get; set; }

    protected void dsGroup_SelectData(object sender, Acms.DataControls.SelectEventArgs<Acms.Bll.TopicGroup> e)
    {
        e.SetData(Acms.Bll.TopicGroup.GetById(Id));
    }

    protected void dsGroup_UpdatingData(object sender, Acms.DataControls.UpdatingDataEventArgs<Acms.Bll.TopicGroup> e)
    {
        if (e.Action == Acms.DataControls.UpdateAction.Insert)
        {
            e.Item.SiteId = AcmsContext.SiteId;
        }
    }

    protected void dv_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
    {
        if(e.Exception == null)
        {
            e.KeepInInsertMode = true;
            ScriptManager.RegisterStartupScript(this, this.GetType(), "returnToParentCall", "returnToParent(true)", true);
        }
    }

    protected void dv_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
    {
        if (e.Exception == null)
        {
            e.KeepInEditMode = true;
            ScriptManager.RegisterStartupScript(this, this.GetType(), "returnToParentCall", "returnToParent(true)", true);
        }
    }
}
